package com.dykj.fireFighting.web.base.enterprise.controller;

import com.dykj.fireFighting.api.base.enterprise.entity.Enterprise;
import com.dykj.fireFighting.api.base.enterprise.service.IEnterpriseService;
import com.dykj.fireFighting.api.base.rescue.entity.RescueInfo;
import com.dykj.fireFighting.api.base.rescue.service.IRescueInfoService;
import com.dykj.fireFighting.common.core.api.CommonResult;
import com.dykj.fireFighting.common.core.vo.LoginUserVo;
import com.dykj.fireFighting.web.base.shiro.ShiroUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description 企业关联救援单位Controller
 * @Author JacksonTu
 * @Date 2018/12/17 11:14
 */
@Slf4j
@Api(value = "企业接口", tags = {"企业接口"})
@RestController
@RequestMapping("/enterprise/rescue")
public class EnterpriseRescueController {


    @DubboReference
    private IEnterpriseService enterpriseService;
    @DubboReference
    private IRescueInfoService rescueInfoService;

    /**
     * 企业列表
     *
     * @return
     */
    @ApiOperation(value = "获取社会单位对应的监控中心下的救援单位信息", notes = "获取社会单位对应的监控中心下的救援单位信息")
    @GetMapping("/list")
    public CommonResult list(String id, String type) {
        Enterprise userEnter = enterpriseService.getById(id);
        if (userEnter != null && userEnter.getEnterpriseType() == 0) {
            String bindingCode = userEnter.getBindingCode();
            if (StringUtils.isNotBlank(bindingCode)) {
                Enterprise enterprise = enterpriseService.getInfoByBindingCode(bindingCode);
                if (enterprise != null) {
                    //根据企业ID及类型获取 救援单位及医院信息
                    List<RescueInfo> list = rescueInfoService.getList(enterprise.getId().toString(), Integer.parseInt(type), null);
                    return CommonResult.success(list);
                }
            }
        }
        return CommonResult.failed("获取失败");
    }

    /**
     * 获取监控中心下的救援单位信息
     *
     * @return
     */
    @ApiOperation(value = "获取监控中心下的救援单位信息", notes = "获取监控中心下的救援单位信息")
    @GetMapping("/queryRescueInfoList")
    public CommonResult queryRescueInfoList() {
        LoginUserVo loginUserVo = ShiroUtil.getUser();
        String bindingCode = loginUserVo.getBindingCode();
        if (StringUtils.isNotBlank(bindingCode)) {
            Enterprise enterprise = enterpriseService.getInfoByBindingCode(bindingCode);
            if (enterprise != null) {
                //根据企业ID及类型获取 救援单位及医院信息
                List<RescueInfo> list = rescueInfoService.getList(enterprise.getId().toString(), 0, null);
                return CommonResult.success(list);
            }
        }
        return CommonResult.failed("获取失败");
    }

}
